import Vue from 'vue'
import Vuex from 'vuex'
import SockJS from 'sockjs-client';
import Stomp from 'stompjs';
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    stompclient:null,
    msgss:null,
    userMsg:null,
  },
  mutations: {
    startwocket(state,val){
      let socketjs = new SockJS('http://localhost:8081/sock')
      state.stompclient = Stomp.over(socketjs)
      state.stompclient.debug = false
      state.stompclient.connect({"token":val},()=>{
        state.stompclient.subscribe("/topic/mymsg",(data)=>{
          state.msgss =  data.body
        })
        state.stompclient.subscribe("/user/topic/mymsg",(data)=>{
          state.userMsg = data.body
        })
      })
    },
    sendMsg(state,val){
      state.stompclient.send("/app/msgq",{},val)
    },
    sendusermsg(state,val){
      state.stompclient.send("/app/touser",{},val)
    }
  },
  actions: {

  },
  modules: {
  }
})
